package com.laizhenghua.hotel.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.laizhenghua.hotel.utils.PageUtils;
import com.laizhenghua.hotel.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import com.laizhenghua.hotel.entity.HouseEntity;
import com.laizhenghua.hotel.service.HouseService;

/**
 * 
 *
 * @author laizhenghua
 * @email 3299447929@qq.com
 * @date 2021-03-11 15:23:22
 */
@Controller
@RequestMapping("hotel/house")
public class HouseController {
    @Autowired
    private HouseService houseService;

    /**
     * 添加
     */
    @GetMapping("/house/add")
    public String toAddHousePage() {
        return "admin/house/add";
    }
    /**
     * 编辑
     */
    @GetMapping("/house/edit.do")
    public String toEditHousePage(Integer id,Model model){
        HouseEntity houseEntity = houseService.getById(id);
        model.addAttribute("model",houseEntity);
        return "admin/house/edit";
    }
    /**
     * 删除
     */
    @GetMapping("/house/delete.do")
    @ResponseBody
    public R deleteHouse(Integer id){
        return R.ok();
    }
    /**
     * 后台跳转至房间管理页面
     */
    @GetMapping("/house/list")
    public String toHouseListPage(Model model) {
        List<HouseEntity> houseEntityList = houseService.list();
        model.addAttribute("list",houseEntityList);
        return "admin/house/list";
    }
    /**
     * 列表
     */
    @RequestMapping("/list")
    @ResponseBody
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = houseService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @ResponseBody
    public R info(@PathVariable("id") Integer id){
		HouseEntity house = houseService.getById(id);

        return R.ok().put("house", house);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @ResponseBody
    public R save(@RequestBody HouseEntity house){
		houseService.save(house);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @ResponseBody
    public R update(@RequestBody HouseEntity house){
		houseService.updateById(house);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @ResponseBody
    public R delete(@RequestBody Integer[] ids){
		houseService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
